package org.apache.dolphinscheduler.api.controller;

import org.apache.dolphinscheduler.api.page.PageQuery;
import org.apache.dolphinscheduler.api.page.R;
import org.apache.dolphinscheduler.api.page.TableDataInfo;
import org.apache.dolphinscheduler.api.service.NetworkService;
import org.apache.dolphinscheduler.dao.entity.Network;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 虚拟网络表 前端控制器
 * </p>
 *
 * @author denggh
 * @since 2023-02-08
 */
@RestController
@RequestMapping("/network")
@Api(tags = "虚拟网络 前端控制器")
public class NetworkController {

    @Autowired
    private NetworkService networkService;
    /**
     * 获取虚拟网络列表
     */
    @GetMapping("/list")
    @ApiOperation("获取虚拟网络列表")
    public TableDataInfo<Network> list(Network network, PageQuery pageQuery) {
        return networkService.selectPageNetworkList(network, pageQuery);
    }

    /**
     * 根据虚拟网络编号获取详细信息
     *
     * @param networkId 虚拟网络ID
     */
    @ApiOperation("根据虚拟网络编号获取详细信息")
    @GetMapping(value = "/{networkId}")
    public R<Network> getInfo(@PathVariable Long networkId) {
        return R.ok(networkService.selectNetworkById(networkId));
    }

    /**
     * 新增虚拟网络
     */
    @ApiOperation("新增虚拟网络")
    @PostMapping
    public R<Void> add(@Validated @RequestBody Network network) {

        return R.toAjax(networkService.insertNetwork(network));
    }

    /**
     * 修改虚拟网络
     */
    @ApiOperation("修改虚拟网络")
    @PutMapping
    public R<Void> edit(@Validated @RequestBody Network network) {
        return R.toAjax(networkService.updateNetwork(network));
    }

    /**
     * 删除虚拟网络
     *
     * @param networkId 虚拟网络ID
     */
    @ApiOperation("删除虚拟网络")
    @DeleteMapping("/{networkId}")
    public R<Void> remove(@PathVariable Long networkId) {
        return R.toAjax(networkService.deleteNetworkById(networkId));
    }
}
